package com.plug.entity;

import java.util.Date;

/**
 * 数据源配置
 */
public class PlugDatasource {
    private Long id; //标识

    private String dsName; //数据库别名

    private String dsDriver; //连接驱动

    private String dsUrl; //连接url

    private String dsUsername; //用户名

    private String dsPassword; //密码

    private String dsType; //数据库类型

    private String dsDesc; //数据库名称

    private Date createtime; //创建时间

    private String url;

    public String getUrl() {
        if(dsType.equals("MYSQL")){
            return  getDsUrl().substring(getDsUrl().indexOf("//") + 2, getDsUrl().lastIndexOf("/"));
        } else {
            return getDsUrl().substring(getDsUrl().indexOf(":@") + 2, getDsUrl().lastIndexOf(":"));
        }
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getDsName() {
        return dsName;
    }

    public void setDsName(String dsName) {
        this.dsName = dsName == null ? null : dsName.trim();
    }

    public String getDsDriver() {
        return dsDriver;
    }

    public void setDsDriver(String dsDriver) {
        this.dsDriver = dsDriver == null ? null : dsDriver.trim();
    }

    public String getDsUrl() {
        return dsUrl;
    }

    public void setDsUrl(String dsUrl) {
        this.dsUrl = dsUrl == null ? null : dsUrl.trim();
    }

    public String getDsUsername() {
        return dsUsername;
    }

    public void setDsUsername(String dsUsername) {
        this.dsUsername = dsUsername == null ? null : dsUsername.trim();
    }

    public String getDsPassword() {
        return dsPassword;
    }

    public void setDsPassword(String dsPassword) {
        this.dsPassword = dsPassword == null ? null : dsPassword.trim();
    }

    public String getDsType() {
        return dsType;
    }

    public void setDsType(String dsType) {
        this.dsType = dsType == null ? null : dsType.trim();
    }

    public String getDsDesc() {
        return dsDesc;
    }

    public void setDsDesc(String dsDesc) {
        this.dsDesc = dsDesc == null ? null : dsDesc.trim();
    }

    public Date getCreatetime() {
        return createtime;
    }

    public void setCreatetime(Date createtime) {
        this.createtime = createtime;
    }
}